# encode: utf-8

import os
import shutil


# import json

import sys


modulename = "zhou"
# 获取所有命令行参数
args = sys.argv

# 打印脚本名称
# print("脚本名称:", args[0])

# 打印传递的参数
if len(args) > 1:
    # print("传递的参数:")
    # for i, arg in enumerate(args[1:], start=1):
    #     print(f"参数 {i}: {arg}")
    print(args[1])
    modulename = args[1]
    # raise Exception("ggg")
else:
    # print("没有传递参数。")
    raise Exception("没有传递参数。")

path = os.path.abspath(__file__)

print(path)


newfolder = os.path.join(path, "../","output", f"{modulename}")


# 递归删除文件夹及其内容
try:
    shutil.rmtree(newfolder)
    print(f"文件夹 '{newfolder}' 及其内容删除成功。")
except FileNotFoundError:
    print(f"文件夹 '{newfolder}' 不存在。")

os.mkdir(newfolder)

with open(os.path.join(path, "../input", "diary.vue"), "r", encoding="utf-8") as f:
    homevue = f.read()
    # print(json_data)

# print(homevue)
homevue = homevue.replace("diary", modulename)


with open(
    os.path.join(path, "../output", f"{modulename}", f"{modulename}.vue"),
    "w",
    encoding="utf-8",
) as f:
    f.write(homevue)


with open(
    os.path.join(path, "../input", "diarydialog.vue"), "r", encoding="utf-8"
) as f:
    homedialogvue = f.read()


homedialogvue = homedialogvue.replace("diary", modulename)
with open(
    os.path.join(path, "../output", f"{modulename}", f"{modulename}dialog.vue"),
    "w",
    encoding="utf-8",
) as f:
    f.write(homedialogvue)


def main():
    print("Hello World")


if __name__ == "__main__":
    main()
